module V {
	/**
	 * 只带信息提示和确认按钮的弹窗组件。
	 * 可同时存在多个。
	 * @author none
	 */
    export class Alert extends eui.Component {
    	/** 用来显示提示信息的文本 */
        public messageLabel: eui.Label;
        /** 显示标题 */
        public txtTitle: eui.Label;
        /**
         * 确定按钮
         */
        public okButton: eui.Button;
        private message: string;
        private title: string;
        private buttonLable: string;
        private okHandler: Function;
        private thisObject: any;
        public constructor(message: string, title: string, buttonLable: string, okHandler?: Function, thisObject?: any, autoClose?: boolean) {
            super();
            this.skinName = "AlertSkin";
            this.message = message;
            this.title = title;
            this.buttonLable = buttonLable;
            this.okHandler = okHandler;
            this.thisObject = thisObject;
        }
        public childrenCreated(): void {
            if (this.txtTitle)
                this.txtTitle.text = this.title;
            this.okButton.label = this.buttonLable || this.okButton.label;
            this.messageLabel.textFlow = new egret.HtmlTextParser().parse(this.message);
            this.okButton.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onOKButton, this);
        }
        private onOKButton(event: egret.TouchEvent): void {
            this.okButton.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.onOKButton, this);
            D.App.removeWin(this);
            if (this.okHandler) {
                this.okHandler.apply(this.thisObject);
            }
        }
        /**
         * ALERT的按钮文字
         */
        public static buttonLableString: string;
        /**
         * 显示一个弹窗
         * @param message {string} 提示文字
         * @param okHandler {Function} 按下确定按钮执行的方法
         * @param thisObject {any} 按下确定按钮执行的方法的上下文
         * @returns {how.Alert} 弹窗的实例
         */
        public static show(message: string, okHandler?: Function, thisObject?: any, title?: string, buttonLable?: string, autoClose: boolean = false): V.Alert {
            var alert: Alert = new Alert(message, title, buttonLable, okHandler, thisObject, autoClose);
            D.App.showWin(alert);
            return alert;
        }
    }
}
